export default (data, map) => {
  let view = new Uint8Array(data);

  view.forEach((bits, i) => {
    let xtxt = {};

    xtxt.data = bits;
    xtxt.type = types[bits].type;
    xtxt.label = types[bits].label;

    if (xtxt.type == 'sign') {
      xtxt.sign = map._segmentData.XLAB[bits];
    }

    if (xtxt.type == 'microsim') {
      xtxt.microsimId = bits - 51;
      xtxt.microsimLabel = map._segmentData.XLAB[bits];

      let xmic = map._segmentData.XMIC[xtxt.microsimId];

      if (xmic !== undefined) {
        xtxt.microsimBuilding = xmic.building;
        xtxt.microsimData1 = xmic.data1;
        xtxt.microsimData2 = xmic.data2;
        xtxt.microsimData3 = xmic.data3;
        xtxt.microsimData4 = xmic.data4;
      }
    }

    if (xtxt.type == 'disaster'){
      xtxt.disaster = true;
    }

    map.cells[i]._segmentData.XTXT = xtxt;
  });
};

let types = {
  0x00: { type: null, label: null, reference: null },
  0x01: { type: 'sign', label: 'Sign 0', reference: 'XLAB' },
  0x02: { type: 'sign', label: 'Sign 1', reference: 'XLAB' },
  0x03: { type: 'sign', label: 'Sign 2', reference: 'XLAB' },
  0x04: { type: 'sign', label: 'Sign 3', reference: 'XLAB' },
  0x05: { type: 'sign', label: 'Sign 4', reference: 'XLAB' },
  0x06: { type: 'sign', label: 'Sign 5', reference: 'XLAB' },
  0x07: { type: 'sign', label: 'Sign 6', reference: 'XLAB' },
  0x08: { type: 'sign', label: 'Sign 7', reference: 'XLAB' },
  0x09: { type: 'sign', label: 'Sign 8', reference: 'XLAB' },
  0x0A: { type: 'sign', label: 'Sign 9', reference: 'XLAB' },
  0x0B: { type: 'sign', label: 'Sign 10', reference: 'XLAB' },
  0x0C: { type: 'sign', label: 'Sign 11', reference: 'XLAB' },
  0x0D: { type: 'sign', label: 'Sign 12', reference: 'XLAB' },
  0x0E: { type: 'sign', label: 'Sign 13', reference: 'XLAB' },
  0x0F: { type: 'sign', label: 'Sign 14', reference: 'XLAB' },
  0x10: { type: 'sign', label: 'Sign 15', reference: 'XLAB' },
  0x11: { type: 'sign', label: 'Sign 16', reference: 'XLAB' },
  0x12: { type: 'sign', label: 'Sign 17', reference: 'XLAB' },
  0x13: { type: 'sign', label: 'Sign 18', reference: 'XLAB' },
  0x14: { type: 'sign', label: 'Sign 19', reference: 'XLAB' },
  0x15: { type: 'sign', label: 'Sign 20', reference: 'XLAB' },
  0x16: { type: 'sign', label: 'Sign 21', reference: 'XLAB' },
  0x17: { type: 'sign', label: 'Sign 22', reference: 'XLAB' },
  0x18: { type: 'sign', label: 'Sign 23', reference: 'XLAB' },
  0x19: { type: 'sign', label: 'Sign 24', reference: 'XLAB' },
  0x1A: { type: 'sign', label: 'Sign 25', reference: 'XLAB' },
  0x1B: { type: 'sign', label: 'Sign 26', reference: 'XLAB' },
  0x1C: { type: 'sign', label: 'Sign 27', reference: 'XLAB' },
  0x1D: { type: 'sign', label: 'Sign 28', reference: 'XLAB' },
  0x1E: { type: 'sign', label: 'Sign 29', reference: 'XLAB' },
  0x1F: { type: 'sign', label: 'Sign 30', reference: 'XLAB' },
  0x20: { type: 'sign', label: 'Sign 31', reference: 'XLAB' },
  0x21: { type: 'sign', label: 'Sign 32', reference: 'XLAB' },
  0x22: { type: 'sign', label: 'Sign 33', reference: 'XLAB' },
  0x23: { type: 'sign', label: 'Sign 34', reference: 'XLAB' },
  0x24: { type: 'sign', label: 'Sign 35', reference: 'XLAB' },
  0x25: { type: 'sign', label: 'Sign 36', reference: 'XLAB' },
  0x26: { type: 'sign', label: 'Sign 37', reference: 'XLAB' },
  0x27: { type: 'sign', label: 'Sign 38', reference: 'XLAB' },
  0x28: { type: 'sign', label: 'Sign 39', reference: 'XLAB' },
  0x29: { type: 'sign', label: 'Sign 40', reference: 'XLAB' },
  0x2A: { type: 'sign', label: 'Sign 41', reference: 'XLAB' },
  0x2B: { type: 'sign', label: 'Sign 42', reference: 'XLAB' },
  0x2C: { type: 'sign', label: 'Sign 43', reference: 'XLAB' },
  0x2D: { type: 'sign', label: 'Sign 44', reference: 'XLAB' },
  0x2E: { type: 'sign', label: 'Sign 45', reference: 'XLAB' },
  0x2F: { type: 'sign', label: 'Sign 46', reference: 'XLAB' },
  0x30: { type: 'sign', label: 'Sign 47', reference: 'XLAB' },
  0x31: { type: 'sign', label: 'Sign 48', reference: 'XLAB' },
  0x32: { type: 'sign', label: 'Sign 49', reference: 'XLAB' },
  0x33: { type: 'microsim', label: 'Unknown Microsimulator 0', reference: 'XMIC' },
  0x34: { type: 'microsim', label: 'Bus System Microsimulator 1', reference: 'XMIC' },
  0x35: { type: 'microsim', label: 'Rail System Microsimulator 2', reference: 'XMIC' },
  0x36: { type: 'microsim', label: 'Subway System Microsimulator 3', reference: 'XMIC' },
  0x37: { type: 'microsim', label: 'Wind Power Microsimulator 4', reference: 'XMIC' },
  0x38: { type: 'microsim', label: 'Hydro Power Microsimulator 5', reference: 'XMIC' },
  0x39: { type: 'microsim', label: 'Park System Microsimulator 6', reference: 'XMIC' },
  0x3A: { type: 'microsim', label: 'Museum System Microsimulator 7', reference: 'XMIC' },
  0x3B: { type: 'microsim', label: 'Library System Microsimulator 8', reference: 'XMIC' },
  0x3C: { type: 'microsim', label: 'Marina System Microsimulator 9', reference: 'XMIC' },
  0x3D: { type: 'microsim', label: 'Microsimulator 10', reference: 'XMIC' },
  0x3E: { type: 'microsim', label: 'Microsimulator 11', reference: 'XMIC' },
  0x3F: { type: 'microsim', label: 'Microsimulator 12', reference: 'XMIC' },
  0x40: { type: 'microsim', label: 'Microsimulator 13', reference: 'XMIC' },
  0x41: { type: 'microsim', label: 'Microsimulator 14', reference: 'XMIC' },
  0x42: { type: 'microsim', label: 'Microsimulator 15', reference: 'XMIC' },
  0x43: { type: 'microsim', label: 'Microsimulator 16', reference: 'XMIC' },
  0x44: { type: 'microsim', label: 'Microsimulator 17', reference: 'XMIC' },
  0x45: { type: 'microsim', label: 'Microsimulator 18', reference: 'XMIC' },
  0x46: { type: 'microsim', label: 'Microsimulator 19', reference: 'XMIC' },
  0x47: { type: 'microsim', label: 'Microsimulator 20', reference: 'XMIC' },
  0x48: { type: 'microsim', label: 'Microsimulator 21', reference: 'XMIC' },
  0x49: { type: 'microsim', label: 'Microsimulator 22', reference: 'XMIC' },
  0x4A: { type: 'microsim', label: 'Microsimulator 23', reference: 'XMIC' },
  0x4B: { type: 'microsim', label: 'Microsimulator 24', reference: 'XMIC' },
  0x4C: { type: 'microsim', label: 'Microsimulator 25', reference: 'XMIC' },
  0x4D: { type: 'microsim', label: 'Microsimulator 26', reference: 'XMIC' },
  0x4E: { type: 'microsim', label: 'Microsimulator 27', reference: 'XMIC' },
  0x4F: { type: 'microsim', label: 'Microsimulator 28', reference: 'XMIC' },
  0x50: { type: 'microsim', label: 'Microsimulator 29', reference: 'XMIC' },
  0x51: { type: 'microsim', label: 'Microsimulator 30', reference: 'XMIC' },
  0x52: { type: 'microsim', label: 'Microsimulator 31', reference: 'XMIC' },
  0x53: { type: 'microsim', label: 'Microsimulator 32', reference: 'XMIC' },
  0x54: { type: 'microsim', label: 'Microsimulator 33', reference: 'XMIC' },
  0x55: { type: 'microsim', label: 'Microsimulator 34', reference: 'XMIC' },
  0x56: { type: 'microsim', label: 'Microsimulator 35', reference: 'XMIC' },
  0x57: { type: 'microsim', label: 'Microsimulator 36', reference: 'XMIC' },
  0x58: { type: 'microsim', label: 'Microsimulator 37', reference: 'XMIC' },
  0x59: { type: 'microsim', label: 'Microsimulator 38', reference: 'XMIC' },
  0x5A: { type: 'microsim', label: 'Microsimulator 39', reference: 'XMIC' },
  0x5B: { type: 'microsim', label: 'Microsimulator 40', reference: 'XMIC' },
  0x5C: { type: 'microsim', label: 'Microsimulator 41', reference: 'XMIC' },
  0x5D: { type: 'microsim', label: 'Microsimulator 42', reference: 'XMIC' },
  0x5E: { type: 'microsim', label: 'Microsimulator 43', reference: 'XMIC' },
  0x5F: { type: 'microsim', label: 'Microsimulator 44', reference: 'XMIC' },
  0x60: { type: 'microsim', label: 'Microsimulator 45', reference: 'XMIC' },
  0x61: { type: 'microsim', label: 'Microsimulator 46', reference: 'XMIC' },
  0x62: { type: 'microsim', label: 'Microsimulator 47', reference: 'XMIC' },
  0x63: { type: 'microsim', label: 'Microsimulator 48', reference: 'XMIC' },
  0x64: { type: 'microsim', label: 'Microsimulator 49', reference: 'XMIC' },
  0x65: { type: 'microsim', label: 'Microsimulator 50', reference: 'XMIC' },
  0x66: { type: 'microsim', label: 'Microsimulator 51', reference: 'XMIC' },
  0x67: { type: 'microsim', label: 'Microsimulator 52', reference: 'XMIC' },
  0x68: { type: 'microsim', label: 'Microsimulator 53', reference: 'XMIC' },
  0x69: { type: 'microsim', label: 'Microsimulator 54', reference: 'XMIC' },
  0x6A: { type: 'microsim', label: 'Microsimulator 55', reference: 'XMIC' },
  0x6B: { type: 'microsim', label: 'Microsimulator 56', reference: 'XMIC' },
  0x6C: { type: 'microsim', label: 'Microsimulator 57', reference: 'XMIC' },
  0x6D: { type: 'microsim', label: 'Microsimulator 58', reference: 'XMIC' },
  0x6E: { type: 'microsim', label: 'Microsimulator 59', reference: 'XMIC' },
  0x6F: { type: 'microsim', label: 'Microsimulator 60', reference: 'XMIC' },
  0x70: { type: 'microsim', label: 'Microsimulator 61', reference: 'XMIC' },
  0x71: { type: 'microsim', label: 'Microsimulator 62', reference: 'XMIC' },
  0x72: { type: 'microsim', label: 'Microsimulator 63', reference: 'XMIC' },
  0x73: { type: 'microsim', label: 'Microsimulator 64', reference: 'XMIC' },
  0x74: { type: 'microsim', label: 'Microsimulator 65', reference: 'XMIC' },
  0x75: { type: 'microsim', label: 'Microsimulator 66', reference: 'XMIC' },
  0x76: { type: 'microsim', label: 'Microsimulator 67', reference: 'XMIC' },
  0x77: { type: 'microsim', label: 'Microsimulator 68', reference: 'XMIC' },
  0x78: { type: 'microsim', label: 'Microsimulator 69', reference: 'XMIC' },
  0x79: { type: 'microsim', label: 'Microsimulator 70', reference: 'XMIC' },
  0x7A: { type: 'microsim', label: 'Microsimulator 71', reference: 'XMIC' },
  0x7B: { type: 'microsim', label: 'Microsimulator 72', reference: 'XMIC' },
  0x7C: { type: 'microsim', label: 'Microsimulator 73', reference: 'XMIC' },
  0x7D: { type: 'microsim', label: 'Microsimulator 74', reference: 'XMIC' },
  0x7E: { type: 'microsim', label: 'Microsimulator 75', reference: 'XMIC' },
  0x7F: { type: 'microsim', label: 'Microsimulator 76', reference: 'XMIC' },
  0x80: { type: 'microsim', label: 'Microsimulator 77', reference: 'XMIC' },
  0x81: { type: 'microsim', label: 'Microsimulator 78', reference: 'XMIC' },
  0x82: { type: 'microsim', label: 'Microsimulator 79', reference: 'XMIC' },
  0x83: { type: 'microsim', label: 'Microsimulator 80', reference: 'XMIC' },
  0x84: { type: 'microsim', label: 'Microsimulator 81', reference: 'XMIC' },
  0x85: { type: 'microsim', label: 'Microsimulator 82', reference: 'XMIC' },
  0x86: { type: 'microsim', label: 'Microsimulator 83', reference: 'XMIC' },
  0x87: { type: 'microsim', label: 'Microsimulator 84', reference: 'XMIC' },
  0x88: { type: 'microsim', label: 'Microsimulator 85', reference: 'XMIC' },
  0x89: { type: 'microsim', label: 'Microsimulator 86', reference: 'XMIC' },
  0x8A: { type: 'microsim', label: 'Microsimulator 87', reference: 'XMIC' },
  0x8B: { type: 'microsim', label: 'Microsimulator 88', reference: 'XMIC' },
  0x8C: { type: 'microsim', label: 'Microsimulator 89', reference: 'XMIC' },
  0x8D: { type: 'microsim', label: 'Microsimulator 90', reference: 'XMIC' },
  0x8E: { type: 'microsim', label: 'Microsimulator 91', reference: 'XMIC' },
  0x8F: { type: 'microsim', label: 'Microsimulator 92', reference: 'XMIC' },
  0x90: { type: 'microsim', label: 'Microsimulator 93', reference: 'XMIC' },
  0x91: { type: 'microsim', label: 'Microsimulator 94', reference: 'XMIC' },
  0x92: { type: 'microsim', label: 'Microsimulator 95', reference: 'XMIC' },
  0x93: { type: 'microsim', label: 'Microsimulator 96', reference: 'XMIC' },
  0x94: { type: 'microsim', label: 'Microsimulator 97', reference: 'XMIC' },
  0x95: { type: 'microsim', label: 'Microsimulator 98', reference: 'XMIC' },
  0x96: { type: 'microsim', label: 'Microsimulator 99', reference: 'XMIC' },
  0x97: { type: 'microsim', label: 'Microsimulator 100', reference: 'XMIC' },
  0x98: { type: 'microsim', label: 'Microsimulator 101', reference: 'XMIC' },
  0x99: { type: 'microsim', label: 'Microsimulator 102', reference: 'XMIC' },
  0x9A: { type: 'microsim', label: 'Microsimulator 103', reference: 'XMIC' },
  0x9B: { type: 'microsim', label: 'Microsimulator 104', reference: 'XMIC' },
  0x9C: { type: 'microsim', label: 'Microsimulator 105', reference: 'XMIC' },
  0x9D: { type: 'microsim', label: 'Microsimulator 106', reference: 'XMIC' },
  0x9E: { type: 'microsim', label: 'Microsimulator 107', reference: 'XMIC' },
  0x9F: { type: 'microsim', label: 'Microsimulator 108', reference: 'XMIC' },
  0xA0: { type: 'microsim', label: 'Microsimulator 109', reference: 'XMIC' },
  0xA1: { type: 'microsim', label: 'Microsimulator 110', reference: 'XMIC' },
  0xA2: { type: 'microsim', label: 'Microsimulator 111', reference: 'XMIC' },
  0xA3: { type: 'microsim', label: 'Microsimulator 112', reference: 'XMIC' },
  0xA4: { type: 'microsim', label: 'Microsimulator 113', reference: 'XMIC' },
  0xA5: { type: 'microsim', label: 'Microsimulator 114', reference: 'XMIC' },
  0xA6: { type: 'microsim', label: 'Microsimulator 115', reference: 'XMIC' },
  0xA7: { type: 'microsim', label: 'Microsimulator 116', reference: 'XMIC' },
  0xA8: { type: 'microsim', label: 'Microsimulator 117', reference: 'XMIC' },
  0xA9: { type: 'microsim', label: 'Microsimulator 118', reference: 'XMIC' },
  0xAA: { type: 'microsim', label: 'Microsimulator 119', reference: 'XMIC' },
  0xAB: { type: 'microsim', label: 'Microsimulator 120', reference: 'XMIC' },
  0xAC: { type: 'microsim', label: 'Microsimulator 121', reference: 'XMIC' },
  0xAD: { type: 'microsim', label: 'Microsimulator 122', reference: 'XMIC' },
  0xAE: { type: 'microsim', label: 'Microsimulator 123', reference: 'XMIC' },
  0xAF: { type: 'microsim', label: 'Microsimulator 124', reference: 'XMIC' },
  0xB0: { type: 'microsim', label: 'Microsimulator 125', reference: 'XMIC' },
  0xB1: { type: 'microsim', label: 'Microsimulator 126', reference: 'XMIC' },
  0xB2: { type: 'microsim', label: 'Microsimulator 127', reference: 'XMIC' },
  0xB3: { type: 'microsim', label: 'Microsimulator 128', reference: 'XMIC' },
  0xB4: { type: 'microsim', label: 'Microsimulator 129', reference: 'XMIC' },
  0xB5: { type: 'microsim', label: 'Microsimulator 130', reference: 'XMIC' },
  0xB6: { type: 'microsim', label: 'Microsimulator 131', reference: 'XMIC' },
  0xB7: { type: 'microsim', label: 'Microsimulator 132', reference: 'XMIC' },
  0xB8: { type: 'microsim', label: 'Microsimulator 133', reference: 'XMIC' },
  0xB9: { type: 'microsim', label: 'Microsimulator 134', reference: 'XMIC' },
  0xBA: { type: 'microsim', label: 'Microsimulator 135', reference: 'XMIC' },
  0xBB: { type: 'microsim', label: 'Microsimulator 136', reference: 'XMIC' },
  0xBC: { type: 'microsim', label: 'Microsimulator 137', reference: 'XMIC' },
  0xBD: { type: 'microsim', label: 'Microsimulator 138', reference: 'XMIC' },
  0xBE: { type: 'microsim', label: 'Microsimulator 139', reference: 'XMIC' },
  0xBF: { type: 'microsim', label: 'Microsimulator 140', reference: 'XMIC' },
  0xC0: { type: 'microsim', label: 'Microsimulator 141', reference: 'XMIC' },
  0xC1: { type: 'microsim', label: 'Microsimulator 142', reference: 'XMIC' },
  0xC2: { type: 'microsim', label: 'Microsimulator 143', reference: 'XMIC' },
  0xC3: { type: 'microsim', label: 'Microsimulator 144', reference: 'XMIC' },
  0xC4: { type: 'microsim', label: 'Microsimulator 145', reference: 'XMIC' },
  0xC5: { type: 'microsim', label: 'Microsimulator 146', reference: 'XMIC' },
  0xC6: { type: 'microsim', label: 'Microsimulator 147', reference: 'XMIC' },
  0xC7: { type: 'microsim', label: 'Microsimulator 148', reference: 'XMIC' },
  0xC8: { type: 'microsim', label: 'Microsimulator 149', reference: 'XMIC' },
  0xC9: { type: 'actor', label: 'Actor 0', reference: 'XTHG' },
  0xCA: { type: 'actor', label: 'Actor 1', reference: 'XTHG' },
  0xCB: { type: 'actor', label: 'Actor 2', reference: 'XTHG' },
  0xCC: { type: 'actor', label: 'Actor 3', reference: 'XTHG' },
  0xCD: { type: 'actor', label: 'Actor 4', reference: 'XTHG' },
  0xCE: { type: 'actor', label: 'Actor 5', reference: 'XTHG' },
  0xCF: { type: 'actor', label: 'Actor 6', reference: 'XTHG' },
  0xD0: { type: 'actor', label: 'Actor 7', reference: 'XTHG' },
  0xD1: { type: 'actor', label: 'Actor 8', reference: 'XTHG' },
  0xD2: { type: 'actor', label: 'Actor 9', reference: 'XTHG' },
  0xD3: { type: 'actor', label: 'Actor 10', reference: 'XTHG' },
  0xD4: { type: 'actor', label: 'Actor 11', reference: 'XTHG' },
  0xD5: { type: 'actor', label: 'Actor 12', reference: 'XTHG' },
  0xD6: { type: 'actor', label: 'Actor 13', reference: 'XTHG' },
  0xD7: { type: 'actor', label: 'Actor 14', reference: 'XTHG' },
  0xD8: { type: 'actor', label: 'Actor 15', reference: 'XTHG' },
  0xD9: { type: 'actor', label: 'Actor 16', reference: 'XTHG' },
  0xDA: { type: 'actor', label: 'Actor 17', reference: 'XTHG' },
  0xDB: { type: 'actor', label: 'Actor 18', reference: 'XTHG' },
  0xDC: { type: 'actor', label: 'Actor 19', reference: 'XTHG' },
  0xDD: { type: 'actor', label: 'Actor 20', reference: 'XTHG' },
  0xDE: { type: 'actor', label: 'Actor 21', reference: 'XTHG' },
  0xDF: { type: 'actor', label: 'Actor 22', reference: 'XTHG' },
  0xE0: { type: 'actor', label: 'Actor 23', reference: 'XTHG' },
  0xE1: { type: 'actor', label: 'Actor 24', reference: 'XTHG' },
  0xE2: { type: 'actor', label: 'Actor 25', reference: 'XTHG' },
  0xE3: { type: 'actor', label: 'Actor 26', reference: 'XTHG' },
  0xE4: { type: 'actor', label: 'Actor 27', reference: 'XTHG' },
  0xE5: { type: 'actor', label: 'Actor 28', reference: 'XTHG' },
  0xE6: { type: 'actor', label: 'Actor 29', reference: 'XTHG' },
  0xE7: { type: 'actor', label: 'Actor 30', reference: 'XTHG' },
  0xE8: { type: 'actor', label: 'Actor 31', reference: 'XTHG' },
  0xE9: { type: 'actor', label: 'Actor 32', reference: 'XTHG' },
  0xEA: { type: 'actor', label: 'Actor 33', reference: 'XTHG' },
  0xEB: { type: 'actor', label: 'Actor 34', reference: 'XTHG' },
  0xEC: { type: 'actor', label: 'Actor 35', reference: 'XTHG' },
  0xED: { type: 'actor', label: 'Actor 36', reference: 'XTHG' },
  0xEE: { type: 'actor', label: 'Actor 37', reference: 'XTHG' },
  0xEF: { type: 'actor', label: 'Actor 38', reference: 'XTHG' },
  0xF0: { type: 'actor', label: 'Actor 39', reference: 'XTHG' },
  0xF1: { type: 'unknown', label: 'Unknown Reference 0 - 0xF1', reference: null },
  0xF2: { type: 'unknown', label: 'Unknown Reference 1 - 0xF2', reference: null },
  0xF3: { type: 'unknown', label: 'Unknown Reference 2 - 0xF3', reference: null },
  0xF4: { type: 'unknown', label: 'Unknown Reference 3 - 0xF4', reference: null },
  0xF5: { type: 'unknown', label: 'Unknown Reference 4 - 0xF5', reference: null },
  0xF6: { type: 'unknown', label: 'Unknown Reference 5 - 0xF6', reference: null },
  0xF7: { type: 'unknown', label: 'Unknown Reference 6 - 0xF7', reference: null },
  0xF8: { type: 'unknown', label: 'Unknown Reference 7 - 0xF8', reference: null },
  0xF9: { type: 'unknown', label: 'Unknown Reference 8 - 0xF9', reference: null },
  0xFA: { type: 'sign', label: 'Neighbor Connection', reference: null },
  0xFB: { type: 'disaster', label: 'Toxic Cloud', reference: 'XTHG' },
  0xFC: { type: 'disaster', label: 'Flood', reference: 'XTHG' },
  0xFD: { type: 'disaster', label: 'Rioters 1', reference: 'XTHG' },
  0xFE: { type: 'disaster', label: 'Rioters 2', reference: 'XTHG' },
  0xFF: { type: 'disaster', label: 'Fire', reference: 'XTHG' },
};